// gross, but it works
@import '../../../../../node_modules/codemirror/lib/codemirror';
@import '../../../../../node_modules/codemirror/addon/dialog/dialog';
@import '../../../../../node_modules/codemirror/addon/fold/foldgutter';
@import '../../../../../node_modules/codemirror/addon/lint/lint';
@import '../../../../../node_modules/codemirror/addon/hint/show-hint';

.powercord-quickcss {
  --editor-height: 350px;
  color: var(--text-normal);
  height: var(--editor-height);
  display: flex;
  flex-direction: column;
  position: relative;

  &:not(.popped-out) {
    background-color: var(--background-secondary);
  }

  &-header, &-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;

    > div {
      display: flex;
      align-items: center;

      span {
        margin-right: 10px;
      }
    }

    .button {
      padding: 3px;
      width: 24px;
      height: 24px;
      cursor: pointer;
      -webkit-app-region: no-drag;

      svg {
        width: 100%;
        height: 100%;
      }
    }
  }

  &-header {
    padding: 7px 15px;
  }

  &-footer {
    padding: 10px 15px;
  }

  &-editor {
    height: calc(100% - 72px);
    position: relative;
    flex: 1;

    &:before, &:after {
      content: '';
      display: block;
      box-shadow: var(--elevation-low);
      position: absolute;
      z-index: 69;
      left: 0;
      right: 0;
      height: 1px;
    }

    &:before {
      top: -1px;
    }

    &:after {
      transform: rotate(180deg);
      bottom: -1px;
    }

    &-settings {
      -webkit-app-region: no-drag;
      background-color: var(--background-secondary);
      height: calc(100% + 38px) !important;
      position: absolute !important;
      top: -38px;
      bottom: 0;
      left: 0;
      right: 0;
      z-index: 69;

      > .settings {
        padding: 25px;
      }

      h2 {
        margin: 30px 20px 20px;
      }

      .close {
        &-wrapper {
          position: absolute;
          top: 28px;
          right: 20px;
        }

        padding: 3px;
        width: 24px;
        height: 24px;
        border: 2px #72767d solid;
        border-radius: 50%;
        cursor: pointer;

        svg {
          width: 100%;
          height: 100%;
        }
      }

      .slider-1PF9SW {
        margin: 20px 25px 0;
        width: calc(100% - 50px);
      }

      .markValue-2DwdXI {
        white-space: nowrap;
      }
    }
  }

  &-codemirror {
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .CodeMirror {
    background-color: transparent;
    color: inherit;
    height: 0;
    flex: 1;

    &-hscrollbar, &-vscrollbar {
      background-color: inherit;

      &::-webkit-scrollbar {
        width: 8px;
        height: 8px;
      }

      &::-webkit-scrollbar-thumb {
        border: 2px solid transparent;
        border-radius: 4px;
        background-color: #202225;
        background-clip: padding-box;
      }
    }

    &-scrollbar-filler {
      width: 8px !important;
      height: 8px !important;
      background-color: transparent;
    }

    &-gutters {
      background-color: var(--background-secondary);
      border-right: 1px var(--background-tertiary) solid;
      padding-right: 5px;
    }

    &-foldgutter:first-child, .CodeMirror-gutter-elt:not(.CodeMirror-linenumber):first-child {
      padding-left: 5px;
    }

    &-dialog-top {
      border-color: var(--background-tertiary);
    }

    // @formatter:off
    .cm-tag { color: #ce9763; }
    .cm-qualifier { color: #0fa0ce; }
    .cm-property, .cm-meta, .cm-variable-3 { color: #4cc558; }
    .cm-number { color: #ffa427; };
    .cm-atom, .cm-keyword { color: #ffcc37; };
    .cm-string, .cm-comment { color: #a76200; }
    .cm-callee { color: #f49898; }
    .cm-variable-2 { color: #88adc5; }
    .cm-searching { background-color: rgba(250, 166, 26, 0.2); }
    .cm-error { border-bottom: 2px #f04747 dotted; }

    &-foldmarker { color: #7289da; text-shadow: none; font-weight: bold; }
    &-activeline-background { background: var(--background-message-hover); }
    &-matchingbracket { outline: 1px solid grey; color:red !important; }
    &-selected { background-color: var(--background-tertiary) !important; }
    &-cursor { border-left: 1px solid var(--header-primary); }
    // @formatter:on
  }

  &-resizer {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 6px;
    cursor: s-resize;
  }
}

.CodeMirror-hints {
  z-index: 6969;
  background-color: var(--background-tertiary);
  border-width: 0;

  &::-webkit-scrollbar {
    display: none;
  }

  .CodeMirror-hint {
    color: var(--text-normal);
    padding: 8px 12px;
    margin: 5px 3px;
  }

  .CodeMirror-hint-active {
    color: var(--header-primary);
    background-color: var(--background-secondary);
  }
}

.theme-light .powercord-quickcss .CodeMirror {
  font-weight: 500;

  // @formatter:off
  .cm-tag { color: #ce9a49; }
  .cm-qualifier { color: #0fa0ce; }
  .cm-property, .cm-meta, .cm-variable-3 { color: #359546; }
  .cm-number { color: #ff7813; };
  .cm-atom, .cm-keyword { color: #a68721; };
  .cm-string, .cm-comment { color: #a76200; }
  .cm-callee { color: #bb6570; }
  .cm-variable-2 { color: #7193a5; }
  .cm-searching { background-color: rgba(250, 166, 26, 0.4); }
  // @formatter:on
}

.powercord-quickcss.popout {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;

  .button, .close {
    box-sizing: border-box;
  }

  .powercord-quickcss-header {
    -webkit-app-region: drag;
  }

  .powercord-quickcss-editor {
    flex: 1;
  }
}
